

export function formatDate(dateStr) {
    // 首先检查是否是有效的日期字符串，并尝试创建 Date 对象
    const date = new Date(dateStr);
    if (!(date instanceof Date) || isNaN(date)) {
        return ''; // 或者返回其他默认值
    }

    const padZero = (num) => (num < 10 ? '0' + num : num);

    let year = date.getFullYear();
    let month = padZero(date.getMonth() + 1);
    let day = padZero(date.getDate());
    let hours = date.getHours();
    let minutes = padZero(date.getMinutes());
    let seconds = padZero(date.getSeconds());

    let ampm = hours >= 12 ? '下午' : '上午';
    hours = hours % 12;
    hours = hours ? hours : 12;

    return `${year}-${month}-${day} ${ampm} ${padZero(hours)}:${minutes}:${seconds}`;
}

export function formatStr(str) {
    if (str === null || str === undefined) {
        return '';
    }
    return str;
}

export function formatNumber(num) {
    if (num === null || num === undefined) {
        return 0;
    }
    return num;
}


export function debounce(func, delay) {
    let timer;
    return (...args) => {
        clearTimeout(timer);
        timer = setTimeout(() => {
            func.apply(this, args);
        }, delay);
    };
}
